<?php

namespace app\common\model\common;

use app\common\model\Mod;

/**
 * 服务商表
 */
class PartitionPackage extends Mod
{
    protected $connection = 'mysql';
    protected $name = 'partition_package';

    //根据环境选择显示包名
    public static function getPartitionPackageInfo(): array
    {
        //检测当前环境情况
        $isPro=checkSystemProductionEnv();
        if ($isPro){
            $partitions=self::where('status',1)->whereIn('is_env',[1,2,3])->order('partition_id','asc')->column('partition_name','partition_id');
            $partitionId=self::where('status',1)->whereIn('is_env',[1,2,3])->order('is_default','asc')->order('partition_id','asc')->value('partition_id');
        }else{
            $partitions=self::where('status',1)->where('is_env',4)->order('partition_id','asc')->column('partition_name','partition_id');
            $partitionId=self::where('status',1)->where('is_env',4)->order('is_default','asc')->order('partition_id','asc')->value('partition_id');
        }
        return [$partitionId,$partitions];
    }

    //根据环境获取选项值
    public static function getPartitionPackageOptions(): array
    {
        //检测当前环境情况
        $isPro=checkSystemProductionEnv();
        if ($isPro){
            $partitions=self::where('status',1)->whereIn('is_env',[1,2,3])->order('partition_id','asc')->field(['partition_name as title','partition_id as val'])->select()->toArray();
        }else{
            $partitions=self::where('status',1)->where('is_env',4)->order('partition_id','asc')->field(['partition_name as title','partition_id as val'])->select()->toArray();
        }
        return $partitions;
    }

    //获取分区信息
    public static function getPartitionPackageList($partitionId=''): array{
        $where['status']=1;
        if ($partitionId){
            $where['partition_id']=$partitionId;
        }
        //检测当前环境情况
        $isPro=checkSystemProductionEnv();
        if ($isPro){
            $partitions=self::where($where)->whereIn('is_env',[1,2,3])->order('partition_id','asc')->select()->toArray();
        }else{
            $partitions=self::where($where)->where('is_env',4)->order('partition_id','asc')->select()->toArray();
        }
        return $partitions;
    }

}
